package model.qna;

public class QnAPaggingBean {
	private int nowPage;
	private int totalContents;
	private int onePageForContents = QnACommonContants.CONTENT_NUMBER_PER_PAGE;
	private int oneGruopForPages = QnACommonContants.PAGEGROUP_NUMBER_PER_PAGE;
	public QnAPaggingBean(int nowPage, int totalContents) {
		super();
		this.nowPage = nowPage;
		this.totalContents = totalContents;
	} 

	public int getNowpage(){
		int nowpage = this.nowPage;
		System.out.println("nowPage"+nowpage);
		return nowpage;	
	}
	
	public int getTotalPage(){
		int totlapagecheck = this.totalContents % this.onePageForContents;
		int totalPage=0;
		if(totlapagecheck==0){
			totalPage = this.totalContents / this.onePageForContents;
		}
		else{
			totalPage = this.totalContents / this.onePageForContents +1;
		}
		System.out.println("totalPage"+totalPage);
		return totalPage;
	}
	
	public int getTotalPageGroup(){ // 총 페이지 그룹
		int totalPageGroupcheck = getTotalPage() % this.oneGruopForPages;
		int totalPageGroup = 0;
		
		if(totalPageGroupcheck==0){
			totalPageGroup= getTotalPage() / this.oneGruopForPages;
		}
		else{
			totalPageGroup= getTotalPage() / this.oneGruopForPages + 1;
		}
		System.out.println("totalPageGroup"+totalPageGroup);
		return totalPageGroup;
	}
	
	public int getNowPageGroup(){
		int nowPageGroupCheck =  getNowpage() % this.oneGruopForPages;
		int nowPageGroup  = 0;
		if(nowPageGroupCheck==0){
			nowPageGroup = getNowpage() / this.oneGruopForPages;
		}
		else
			nowPageGroup = getNowpage() / this.oneGruopForPages +1;
		System.out.println("nowPageGroup"+nowPageGroup);
		return nowPageGroup;
	}

	
	public int getStartPageOfPageGroup(){
		int startPageOfPageGroup= this.oneGruopForPages *(getNowPageGroup()-1)+1;
		System.out.println("startPageOfPageGroup"+startPageOfPageGroup);
		return startPageOfPageGroup;
	}
	
	public int getEndPageOfPageGroup(){
		int endPageOfPageGroupCheck = getNowPageGroup() * this.oneGruopForPages;
		int endPageOfPageGroup = 0;
		if(getTotalPage() < endPageOfPageGroupCheck){
			endPageOfPageGroup = getTotalPage();
		}
		else 
			endPageOfPageGroup = endPageOfPageGroupCheck;
		
		System.out.println("endPageOfPageGroup"+endPageOfPageGroup);
		return endPageOfPageGroup;
	}
	public boolean isPreviousPageGroup(){
		boolean flag = false ;
		if(getNowPageGroup() > 1){
			flag  = true;			
		}
		
		System.out.println(flag);
		return flag;
	}
	
	public boolean isNextPageGroup(){
		boolean flag = false ;
		
		if(getNowPageGroup() < getEndPageOfPageGroup()){
			flag = true;
		}
		
		System.out.println(flag);
		return flag;
	}
	
	
}
